package com.winit.generator.task;

import com.winit.generator.framework.AbstractApplicationTask;
import com.winit.generator.framework.context.ApplicationContext;
import com.winit.generator.handler.BaseHandler;
import com.winit.generator.handler.impl.CreateHandler;
import com.winit.generator.model.EntityInfo;

import java.util.List;

public class CreateTask extends AbstractApplicationTask {

    private static String CREATE_FTL = "template/Create.ftl";

    private List<EntityInfo> entityInfos;

    @SuppressWarnings("unchecked")
    @Override
    protected boolean doInternal(ApplicationContext context) {
        logger.info("开始生成实体");

        // 获取实体信息
        entityInfos = (List<EntityInfo>) context.getAttribute("entityInfos");

        BaseHandler<EntityInfo> handler = null;
        for (EntityInfo entityInfo : entityInfos) {
            handler = new CreateHandler(CREATE_FTL, entityInfo);
            handler.execute(context);
        }
        logger.info("生成实体类完成");
        return false;
    }
}
